#include "stdafx.h"
#include "EdgeDetector.h"
#include "imageIterator.h"
#include "cv.h"
#include <omp.h>

void EdgeDetector::process(IplImage *image) {


	int height    = image->height;
	int width     = image->width;
	int step      = image->widthStep;
	uchar *data1      = (uchar *)image->imageData;
	uchar *data2      = (uchar *)output->imageData;

	int i=step;
	for(i=step+1;i<image->imageSize;i++){
		if(abs(data1[i]-data1[i-1])>thresh || abs(data1[i]-data1[i-step])>thresh)
			data2[i]=255;
		else
			data2[i]=0;
	}
}

void EdgeDetector::processOpenMP(IplImage *image) {
	
	int height    = image->height;
	int width     = image->width;
	int step      = image->widthStep;
	uchar *data1      = (uchar *)image->imageData;
	uchar *data2      = (uchar *)output->imageData;

	int i=step;
	int n=image->imageSize;

	
	#pragma omp parallel default(none)\
		shared(n,data1,data2,step) private(i)
	{
		#pragma omp for nowait
		for(i=step+1;i<n;i++)
		{
			if(abs(data1[i]-data1[i-1])>thresh || abs(data1[i]-data1[i-step])>thresh)
				data2[i]=255;
			else
				data2[i]=0;
		}
	}
	
	
}
